/**
 *@author   wuwg
 *@createTime   2018/03/20
 *@updateTime   2018/04/28
 *@description  spin component
 */
/**
 * #item
 *
 * @type        aty-spin
 * @cn          加载中
 * @menu        工具
 * @stPlugin    true
 * @stContainer false
 */
import config from '../../../../config/config.js'

// mixins
import ScrollbarMixins from '../../../../mixins/mixins-scrollbar.js'
// prefix
const prefixCls = config.prefix + '-spin'

export default {
  name: prefixCls,
  mixins: [ScrollbarMixins],
  props: {
    /**
     * #property
     *
     * @name    fix
     * @cn      相对容器进行定位
     * @type    boolean
     * @value   false
     * @description 相对容器进行定位
     */
    fix: {
      type: Boolean,
      default: false
    },
    fullscreen: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      showText: false,
      // used for $Spin
      visible: false
    }
  },
  computed: {
    classes () {
      return [
                `${prefixCls}`,
                {
                  [`${prefixCls}-fix`]: this.fix,
                  [`${prefixCls}-show-text`]: this.showText,
                  [`${prefixCls}-fullscreen`]: this.fullscreen
                }
      ]
    },
    mainClasses () {
      return `${prefixCls}-main`
    },
    dotClasses () {
      return `${prefixCls}-dot`
    },
    textClasses () {
      return `${prefixCls}-text`
    },
    fullscreenVisible () {
      if (this.fullscreen) {
        return this.visible
      } else {
        return true
      }
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.addScrollEffect()
      } else {
        this.removeScrollEffect()
      }
    }
  },
  mounted () {
    this.showText = this.$slots.default !== undefined
  }
}
